<?php

namespace App\Util;


class Sku
{
	public static function generate($data)
	{
		if(empty($data)) {
			return [];
		}
		/*
		$data = 	[
						[
							'name'=>'size',
							'value'=>[['name'=>'31'],['name'=>'32'],['name'=>'33']]
						],
						[
							'name'=>'color',
							'value'=> [['name'=>'red'],[['name'=>'break'],['name'=>'blue']]
						],
						[
							'name'=>'套餐',
							'value'=>[['name'=>'套餐一'],['name'=>'套餐二'],['name'=>'套餐三']]
						]
					]
		*
		*/ 
		$len = count($data);
		$skus = [];

		for($i =0; $i< $len;$i++) {
			$name = $data[$i]['name'];
			$value = $data[$i]['value'];
			if(empty($data[$i]['name']) || empty($data[$i]['value'])){
                 continue;
            }
			if(empty($skus)) {
				$skus = array_column($value, 'name');//初始化规格			
			} else {
				$temp = [];
				foreach($skus as $sku) {
					foreach ($value as $item) {
						$temp[] = $sku.$item['name'];
					}	
				}
				$skus = $temp;
			}
		}
		return $skus;
	}
}